package No1047_remove_all_adjacent_duplicates_in_string

func removeDuplicates(S string) string {
	bytes := []byte(S)
	l := len(bytes)
	var result = make([]byte, 0)
	for i := 0; i < l; i++ {
		rl := len(result)
		if rl == 0 {
			result = append(result, bytes[i])
		} else {
			if result[rl-1] == bytes[i] {
				result = result[:rl-1]
			} else {
				result = append(result, bytes[i])
			}
		}
	}
	return string(result)
}

var Solution = removeDuplicates
